package com.swang.redis.service.facade;

import java.util.Set;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

import com.swang.redis.facade.RedisFacade;
import com.swang.redis.facade.rpc.CommonResult;
import com.swang.redis.facade.rpc.Result;
import com.swang.redis.facade.rpc.ResultFactory;
import com.swang.redis.service.handler.RedisService;

/**
 * @ClassName: SingleSpringRedisFacadeImpl
 * @Description: 单实例spring data redis接口
 * @author swang
 * @date 2017年4月23日 下午7:55:21
 */
@Component(value="singleSpringRedisFacadeImpl")
public class SingleSpringRedisFacadeImpl implements RedisFacade {

	@Autowired
    @Qualifier("redisSigleService")
	private RedisService redisSigleService;

	@Override
	public CommonResult<String> get(String key) {
		return ResultFactory.initCommonResultWithSuccess(redisSigleService.get(key));
	}

	@Override
	public CommonResult<Set<String>> smembers(String key) {
		return ResultFactory.initCommonResultWithSuccess(redisSigleService.sMembers(key));
	}

	@Override
	public CommonResult<Long> sadd(String key, String... value) {
		return ResultFactory.initCommonResultWithSuccess(redisSigleService.sAdd(key, value));
	}

	@Override
	public Result set(String key, String value) {
		redisSigleService.set(key, value);
		return ResultFactory.initResultWithSuccess();
	}

	@Override
	public Result expire(String key, int seconds) {
		redisSigleService.KExpire(key, seconds);
		return ResultFactory.initResultWithSuccess();
	}

	

	@Override
	public CommonResult<Long> scard(String key) {
		return ResultFactory.initCommonResultWithSuccess(redisSigleService.sSCard(key));
	}

	@Override
	public CommonResult<Long> srem(String key, String... value) {
		return privateSrem(key, (Object[])value);
	}
	private CommonResult<Long> privateSrem(String key, Object... value) {
		return ResultFactory.initCommonResultWithSuccess(redisSigleService.sRem(key, value));
	}

}
